package com.pin.zheng.xingmulibrary.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.pin.zheng.xingmulibrary.R;


public class CommomEditDialog extends Dialog implements View.OnClickListener{
    private Context mContext;
    private OnCloseListener listener;
    private EditText content;
    private String contentValue;
    public CommomEditDialog(Context context, int themeResId, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.listener = listener;
    }

    public void setContentValue(String contentValue) {
        this.contentValue = contentValue;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_edit_commom);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {
        TextView tv_cancel = (TextView) findViewById(R.id.cancel);
        TextView tv_submit = (TextView) findViewById(R.id.submit);
        content=findViewById(R.id.content);
        if(!TextUtils.isEmpty(contentValue)){
            content.setText(contentValue);
        }
        tv_cancel.setOnClickListener(this);
        tv_submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.cancel) {
            this.dismiss();
        } else if (id == R.id.submit) {
            if (listener != null) {
                listener.onClick(this, content.getText().toString());
            }
            this.dismiss();
        }
    }

    public interface OnCloseListener {
        void onClick(Dialog dialog, String id);
    }
}
